package dev.bong.controller;

import dev.bong.dto.ApplyDTO;
import dev.bong.pojo.result.Result;
import dev.bong.service.StudentService;
import dev.bong.utils.ThreadLocalUtil;
import dev.bong.vo.ApplyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;



/**
 * @author: bong~
 * @description: TODO
 * @date: 2024/4/14 11:19
 * @version: 1.0
 */

@RestController
@Slf4j
@RequestMapping("/student")
@Api(tags = "学生模块")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/apply/list")
    @ApiOperation(value = "借用申请列表",notes = "审批状态：-1:未审核，0:驳回，1:通过，2:使用完毕")
    public Result<List<ApplyVo>> getApplyList(){


        List<ApplyVo> list=studentService.getApplyList();

        System.out.println(list.toString());
        return Result.success(list);
    }


    @PostMapping("/apply/add")
    @ApiOperation("新增申请")
    public Result addApply(ApplyDTO dto){

        studentService.addApply(dto);
        return Result.success("新增申请，成功！");

    }

    @PutMapping("apply/update")
    @ApiOperation("修改申请")
    public Result updateApply(@RequestBody ApplyDTO dto){
        Integer applyId=dto.getId();
        Integer status=studentService.getStatusById(applyId);
        if(status!=-1){
            return Result.error("该申请已被处理，无法修改");

        }

        studentService.updateApply(dto,applyId);
        return Result.success("修改申请，成功！");

    }



    @PostMapping("/apply/confirm")
    @ApiOperation(value = "确认申请", notes = "审批状态：-1:未审核，0:驳回，1:通过，2:使用完毕")
    public Result confirmApply(Integer applyId){

        studentService.confirmApply(applyId);
        return Result.success("确认申请，成功！");
    }
}
